#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 叶建伟
   @Email: yejw46507@hundsun.com
   @Time: 2022/6/10 16:49
   @File: check_scene_util.py
"""
import re
import time

from 基础公共脚本.公共方法_hui2 import FE
from qturboframe.public_ui.h_ui.type_field import TypeField

def scene_input(labelName,inputName,inputContent):
    '''
    labelName:输入框前面的label名称
    inputName:input默认显示 例如：请输入、长度
    inputContent: 输入内容
    '''
    if inputName:
        FE.input_type(idname={
            'xpath': '//label[contains(text(),"'+labelName+'")]/ancestor::div[@class="h-row"]/descendant::input[@placeholder="'+inputName+'"]'}).set_value(inputContent)
    else:
        FE.input_type(idname={
            'xpath': '//label[contains(text(),"' + labelName + '")]/ancestor::div[@class="h-row"]/descendant::input[@type="text"]'}).set_value(
            inputContent)

def scene_input_money(labelName,inputName,inputContent):
    '''
    labelName:输入框前面的label名称
    inputName:input默认显示 例如：请输入、长度
    inputContent: 输入内容
    '''
    if inputName:
        FE.TypeField(idname={
            'xpath': '//label[contains(text(),"'+labelName+'")]/ancestor::div[@class="h-row"]/descendant::div[contains(@class,"h-typefield")]/input[@class="h-typefield-left"]'}).set_value(inputContent)
    else:
        FE.input_type(idname={
            'xpath': '//label[contains(text(),"' + labelName + '")]/ancestor::div[@class="h-row"]/descendant::input[@type="text"]'}).set_value(
            inputContent)

def scene_check(labelName,checkContent):
    '''
        labelName:下拉框前面的label名称
        checkContent: 下来框选择内容
    '''
    # FE.button(idname={
    #     'xpath': '//label[contains(text(),"'+labelName+'")]/ancestor::div[@class="h-row"]/descendant::span[@class="h-select-placeholder"]'}).click()
    FE.button(idname={
        'xpath': '//label[contains(text(),"'+labelName+'")]/ancestor::div[@class="h-row"]/descendant::i[contains(@class,"h-icon-unfold")]'}).click()
    if checkContent == "全选":
        FE.button(idname={
            'xpath': '//label[contains(text(),"' + labelName + '")]/ancestor::div[@class="h-row"]/descendant::span[text()="全选"]'}).click()
    elif "," in checkContent:
        str_list = re.split(",", checkContent)
        for i in str_list:
            FE.button(idname={
                'xpath': '//label[contains(text(),"' + labelName + '")]/ancestor::div[@class="h-row"]/descendant::li[contains(text(),"' + i + '")]'}).click()
    else:
        FE.button(idname={
            'xpath': '//label[contains(text(),"'+labelName+'")]/ancestor::div[@class="h-row"]/descendant::li[contains(text(),"'+checkContent+'")]'}).click()

def scene_check_index(labelName,checkContent,index):
    '''
        labelName:下拉框前面的label名称
        checkContent: 下来框选择内容
    '''
    FE.button(idname={
        'xpath': '//label[contains(text(),"'+labelName+'")]/ancestor::div[@class="h-row"]/div['+str(index)+']/descendant::i[contains(@class,"h-icon-unfold")]'}).click()
    time.sleep(1)
    if checkContent == "全选":
        FE.button(idname={
            'xpath': '//label[contains(text(),"' + labelName + '")]/ancestor::div[@class="h-row"]/div[' + str(index) + ']/descendant::span[text()="全选"]'}).click()
    elif "," in checkContent:
        str_list = re.split(",", checkContent)
        for i in str_list:
            FE.button(idname={
                'xpath': '//label[contains(text(),"' + labelName + '")]/ancestor::div[@class="h-row"]/div['+str(index)+']/descendant::li[contains(text(),"' + i + '")]'}).click()
    else:
        FE.button(idname={
            'xpath': '//label[contains(text(),"'+labelName+'")]/ancestor::div[@class="h-row"]/div['+str(index)+']/descendant::li[contains(text(),"'+checkContent+'")]'}).click()

def scene_input_index(labelName,inputName,inputContent,index):
    '''
    labelName:输入框前面的label名称
    inputName:input默认显示 例如：请输入、长度
    inputContent: 输入内容
    '''
    if inputName:
        FE.input_type(idname={
            'xpath': '//label[contains(text(),"'+labelName+'")]/ancestor::div[@class="h-row"]/div['+str(index)+']/descendant::input[@placeholder="'+inputName+'"]'}).set_value(inputContent)
    else:
        FE.input_type(idname={
            'xpath': '//label[contains(text(),"' + labelName + '")]/ancestor::div[@class="h-row"]/div['+str(index)+']/descendant::input[@type="text"]'}).set_value(
            inputContent)
